package com.wongsir.springbootdemo.service.impl;

import org.springframework.stereotype.Service;

import com.wongsir.springbootdemo.service.ICommonService;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;

/**
 * @Description:公共接口方法的简单实现
 * @author hjd
 * @date 2018年8月13日
 */
@Service
public class SimpleCommonServiceImpl implements ICommonService{

	@Override
	public String login(String targetUrl, String body, int timeout) {
		HttpResponse httpResponse = HttpRequest.post(targetUrl).body(body).timeout(timeout).execute();
		JSONObject obj = new JSONObject();
		obj.put("status", httpResponse.getStatus());
		obj.put("body", httpResponse.body());
		return obj.toString();
	}
	
	@Override
	public String login(String targetUrl, String body) {
		int timeout = -1;
		return this.login(targetUrl, body, timeout);
	}

}
